package com.vinyl.net 
{
	import flash.net.*;
	import flash.net.URLRequest;
    import flash.net.URLVariables;
	import flash.events.*;
	
	/**
	 * 
	 */
	public class UrlDataService extends EventDispatcher
	{
		public function UrlDataService() 
		{
		}
		
		/**
		 * urlLoader 서버사이드 서버 연결
		 */
		public function urlLoader( url:String, handler:Function, variables:URLVariables = null ):void
		{
			var loader:URLLoader = new URLLoader();
			configureListeners( loader, handler );
			
			var request:URLRequest = new URLRequest(url);
			request.data = variables;
			request.method = URLRequestMethod.POST;    
			
			try 
			{
				loader.load(request);		
			} 
			catch (error:Error)
			{
				trace("Unable to load requested document.");
			}
		}
		
		private function configureListeners(dispatcher:IEventDispatcher, handler:Function ):void 
		{
			dispatcher.addEventListener(Event.COMPLETE, handler );
			dispatcher.addEventListener(Event.OPEN, openHandler);
			dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
			dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
			dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}
		
		private function completeHandler(event:Event):void 
		{
			var loader:URLLoader = URLLoader(event.target);
			var vars:URLVariables = new URLVariables(loader.data);
			
			//trace("completeHandler: " + loader.data);
		}
		
		private function openHandler(event:Event):void {
			//trace("openHandler: " + event);
		}
		
		private function progressHandler(event:ProgressEvent):void {
			//trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
		}

		private function securityErrorHandler(event:SecurityErrorEvent):void {
			//trace("securityErrorHandler: " + event);
		}
		
		private function httpStatusHandler(event:HTTPStatusEvent):void {
			//trace("httpStatusHandler: " + event);
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void {
			//trace("ioErrorHandler: " + event);
			//타이틀, 메세지,        스킨, 타입(0,1,2), 	
			/*
			Alert.show( this, "", "", 7, 0, confirmHandler, cancelHandler, null,  function( modal: MovieClip, o:Object )
			{ 	
				//사용자 정의 콜백핸들러
				
				//modal.y = 0;
				//modal.x = 0;	   
										   
				//modal.getChildByName( "okButton" ).label.htmlText = "<B>확 인</B>";
			} );
			*/
		}
	}

}

